#include "SQLValuesQuery.h"

#include "../SQLExpr.h"
#include "../expr/SQLListExpr.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"

SQLValuesQuery::SQLValuesQuery()
{
  values = std::make_shared<std::list<SQLExpr_ptr>>();
}

SQLExpr_list_ptr  SQLValuesQuery::getValues()
{
  return values;
}

void SQLValuesQuery::addValue(SQLListExpr_ptr value)
{
  value->setParent(SharedObject(SQLValuesQuery));
  values->push_back(value);
}

void SQLValuesQuery::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLValuesQuery)))
  {
    SQLObject_list_ptr  tmp = ListTran::tran_class<SQLExpr, SQLObject>(values);
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(SQLValuesQuery));
}

SQLObject_ptr SQLValuesQuery::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLValuesQuery>(new SQLValuesQuery());
  std::shared_ptr<SQLValuesQuery> x = std::dynamic_pointer_cast<SQLValuesQuery>(clone_tmp);
  // SQLValuesQuery *x = new SQLValuesQuery();
  x->parenthesized = parenthesized;

  auto it_values = values->begin();
  for (int i = 0; i < values->size(); ++i)
  {
    std::advance(it_values, i);
    SQLExpr_ptr value = std::dynamic_pointer_cast<SQLExpr>((*it_values)->clone());
    value->setParent(x);
    x->values->push_back(value);
  }

  return x;
}
